def countStudents(students, sandwiches):
    while students:
        if students[0] == sandwiches[0]:
            students.pop(0)
            sandwiches.pop(0)
        else:
            students.append(students.pop(0))
        
        # 如果队列中所有人都不喜欢堆顶三明治，结束
        if students.count(sandwiches[0]) == 0:
            break

    return len(students)
if __name__ == '__main__':
    students = [1, 1, 0, 0, 1, 0, 1]
    sandwiches = [1, 0, 0, 1, 1, 1, 1]
    print(countStudents(students, sandwiches))